<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">订单</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/">批量发货</a></el-breadcrumb-item>
    </el-breadcrumb>

    <el-button icon="el-icon-refresh" style="float: right"  @click="reload">刷新</el-button>

    <!-- 表格开始 -->
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="id" label="订单编号"></el-table-column>
      <el-table-column prop="receiverContact" label="收货人" width="170"></el-table-column>
      <el-table-column prop="receiverMobile" label="手机号码" width="170"></el-table-column>
      <el-table-column prop="shippingName" label="物流名称" width="170">百事</el-table-column>
      <el-table-column prop="logisticId" label="配送方式">
        <template slot-scope="scope">
          <el-select v-model="scope.row.logisticId" placeholder="请选择物流公司">
            <el-option
              v-for="item in logistics"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column prop="shippingCode" label="物流单号" width="170">
        <template slot-scope="scope">
            <el-input v-model="scope.row.shippingCode"  size="small"/>
        </template>
      </el-table-column>
    </el-table> 
    <!-- 表格结束 -->

    <span style="padding-top:15px">
      <el-button size="medium">取消</el-button>
      <el-button size="medium" type="primary" @click="batchSent()">确定</el-button>
    </span>

  </div>
</template>

<script>

export default {
  async created () {
    this.getBrandList();
    this.ordersId = this.$route.query.ordersId
    this.searchMap.ordersId = this.$route.query.ordersId
  },
  data () {
    return {
      tableData: [], // 表格数据
      currentPage: 1, // 当前页码
      pageSize: 10, // 页大小
      pageSizeList: [10, 20, 50, 100, 500], // 页大小列表
      total: 0, // 总记录数
      searchMap: {}, // 查询表单对象
      // 添加表单
      // 表单label的宽度
      formLabelWidth: '120px',
      ordersId: [],
      logistics: []
    }
  },
  methods: {
    // 查询列表
    async getBrandList () {
      console.log(this.searchMap);
      const { data: res } = await this.$http.post(`/orders/order/findByOids`, this.searchMap)
      const { data: ress } = await this.$http.get(`/orders/logistic/findAll`)
      this.logistics = ress.data
      this.tableData = res.data
    },
    // 查询
    onSubmit () {
      this.getBrandList()
    },
    // 刷新
    reload () {
      window.location.reload()
    },
    lookOrder () {},
    //确认发货
    async batchSent () {
      const { data: res } = await this.$http.post(`/orders/order/batchSend`, this.tableData)
      if (res.code !== 200) {
        this.$message.error("发货失败");
        return 
      }
      this.$message.success("发货成功")
      this.$route.push("/order/order")
    }
  }
}
</script>

<style scoped>
</style>>
